package com.lzz.bottomencapsulation.popupwindow;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;


/**
 * Created by apple on 17/3/21.
 */

public abstract class BasePopupWindow extends PopupWindow {
    protected View.OnClickListener onClickListener;
    protected View contentView;
    protected Activity context;
    protected LayoutInflater inflater;
    protected View parentView;

    public BasePopupWindow(Activity context, View parentView) {
        super(context);
        this.context = context;
        this.parentView = parentView;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        setView();

        if (null != contentView) {
            setContentView(contentView);
        }
        /**
         * 设置可以获取集点
         */
        setFocusable(true);
        /**
         * 设置点击外边可以消失
         */
        setOutsideTouchable(true);
    }

    /**
     * 设置视图
     */
    protected abstract void setView();

    public void Show(int Gravity) {
        if (!isShowing()) {
            showAtLocation(parentView, Gravity, 0, 0);
        }
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }
}
